package leetcode;

import java.util.Objects;
import java.util.TreeSet;

public class leet220 {
    public static void main(String[] args) {
        TreeSet<Integer> set = new TreeSet<>();
        set.add(2);
        Integer floor = set.floor(2);
        System.out.println(floor != null);
    }

    public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) {
        TreeSet<Integer> set = new TreeSet<>();
        for(int i = 0; i < nums.length; i ++){
            int left = set.ceiling(nums[i] - t);
            if(!Objects.isNull(left) && left <= nums[i] + t){
                return true;
            }
            if(set.size() >= k){
                set.remove(nums[i-k]);
            }
        }
        return false;
    }
}
